-
Notifications
You must be signed in to change notification settings - Fork 174
homework 4 #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
homework 4 #174
Conversation
|
|
||
| @Component.Factory | ||
| interface Factory { | ||
| fun build(@BindsInstance app: App) : ApplicationComponent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- обычно метод в
Factoryназываютcreate,buildиспользуют вBuilder - тут нужно пробросить
Сontext, а неApp - нужно использовать квалификатор
@ApplicationContext, потому что он может бытьActivityContext
| import javax.inject.Qualifier | ||
|
|
||
| @MainActivityScope | ||
| @Component( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это должен быть Subcomponent для ApplicationComponent, а не отдельный компонент
|
|
||
| @Component.Factory | ||
| interface Factory { | ||
| fun build(@BindsInstance appContext: Context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут не нужно прокидывать и appContext и activity, достаточно будет @MainActivityContext context: Context, соответственно нужно создать @ApplicationContext аннотации:
@Qualifier
annotation class ApplicationContext
| class ReceiverViewModel( | ||
| class ReceiverViewModel @Inject constructor( | ||
| private val state: ColorState, | ||
| private val context: Context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут мы получаем @ApplicationContext
| } | ||
| } | ||
|
|
||
| val MainActivity.Component: MainActivityComponent get() = this.component |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
обычно свойства с маленькой буквы MainActivity.сomponent
| private val color: ColorSaver, | ||
| private val colorGenerator: ColorGenerator, | ||
| private val context: Context | ||
| @param:MainActivityContext private val context: Context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут получаем @ActivityContext
| annotation class MainActivityContext | ||
|
|
||
| @Module | ||
| object MainActivityModule { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
этот модуль будет не нужен
No description provided.